package main

import (
	"encoding/json"
	"fmt"
)

type Movie struct {
	Title  string   `json:"title"`
	Year   int      `josn:"year"`
	Price  int      `json:"price"`
	Actors []string `json:"actors"`
}

func main() {
	movie := Movie{"喜剧之王", 2000, 15, []string{"周星驰", "张柏芝"}}
	fmt.Printf("Type:%T value:%v\n",movie,movie)
	// 编码，将movie转换成json字符串格式
	jsonstr, _ := json.Marshal(movie)
	fmt.Printf("%s \n",jsonstr)

	// 反编码，将json字符串转换为对应的数据类型
	newMovie := Movie{}
	_ = json.Unmarshal(jsonstr,&newMovie)
	// if err != nil{
	// 	fmt.Println("json marshal error",err)
	// 	return
	// } else {
	// 	fmt.Printf("Type:%T value:%v\n",newMovie,newMovie)
	// }
	fmt.Printf("Type:%T value:%v\n",newMovie,newMovie)
}
